package org.linlinjava.litemall.db.service;

import lombok.extern.slf4j.Slf4j;
import org.linlinjava.litemall.db.dao.VendorWithdrawMapper;
import org.linlinjava.litemall.db.domain.VendorWithdraw;
import org.linlinjava.litemall.db.domain.VendorWithdrawExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
public class VendorWithdrawService {

    @Autowired
    private VendorWithdrawMapper vendorWithdrawMapper;

    public int add(VendorWithdraw vendorWithdraw) {
        vendorWithdraw.setAddTime(LocalDateTime.now());
        vendorWithdraw.setUpdateTime(LocalDateTime.now());
        vendorWithdraw.setDeleted(VendorWithdraw.NOT_DELETED);
        return vendorWithdrawMapper.insert(vendorWithdraw);
    }

    public int update(VendorWithdraw vendorWithdraw) {
        vendorWithdraw.setUpdateTime(LocalDateTime.now());
        return vendorWithdrawMapper.updateByPrimaryKey(vendorWithdraw);
    }

    public List<VendorWithdraw> findByVendorId(Long vendorId) {
        VendorWithdrawExample example = new VendorWithdrawExample();
        example.or().andVendorIdEqualTo(vendorId);

        example.orderBy(" payment_time DESC");
        return vendorWithdrawMapper.selectByExample(example);
    }
}